﻿'use strict';
app
    // Login Box controller 
    .controller('ContactController', [
        '$rootScope', '$scope', '$state', '$localStorage', '$http', '$modal', function ($rootScope, $scope, $state, $localStorage, $http, $modal) {
            $scope.user = $localStorage.user;            
            $scope.processing = false;
            $scope.data = { Subject: "", Message: "", Email: "" }
            if ($scope.user) {
                $scope.data.Email = $scope.user.Email
            }
            $scope.popup = function (windowClass) {
                 $modal.open({
                     windowClass: windowClass,
                     templateUrl: "WarningModal",
                     controller: "ContactModalInstanceCtrl",
                     size: "sm",
                     resolve: {
                         messeger: function () {
                             return $scope.messeger;
                         },
                         title: function () {
                             return $scope.title;
                         }
                     }
                 })
            },
            $scope.doContact = function (data) {
                $scope.processing = true;
                $http.post($rootScope.APIUrl + 'Contact', { contactform: data }).then(function successCallback(resp) {
                    $scope.messeger = resp.data.Messeger;
                    $scope.processing = false;
                    if (resp.data.Status) {
                        $scope.title = "Send Contact Success";
                    } else {
                        $scope.title = "Send Contact UnSuccess";
                    }
                    $scope.popup("modal-message modal-success");
                    
                }, function errorCallback(resp) {
                    $scope.processing = false;
                    $scope.popup("modal-message modal-danger");
                })
            }
        }
    ])
app.controller('ContactModalInstanceCtrl', function ($scope, $modalInstance, messeger, title) {    
    $scope.messeger = messeger;
    $scope.title = title;
    $scope.ok = function () {
        $modalInstance.close();
    };
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };
});